package com.yanfan.building.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.building.domain.AreaBuildingFloor;
import com.yanfan.building.service.IAreaBuildingFloorService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 区域楼栋楼层Controller
 *
 * @author genluo
 * @date 2024-10-09
 */
@Api(tags = "区域楼栋楼层")
@RestController
@RequestMapping("/building/buildingFloor")
public class AreaBuildingFloorController extends BaseController {
    @Autowired
    private IAreaBuildingFloorService areaBuildingFloorService;

    /**
     * 查询区域楼栋楼层列表
     */
    @ApiOperation("区域楼栋楼层分页列表")
    @PreAuthorize("@ss.hasPermi('building:buildingFloor:list')")
    @GetMapping("/list")
    public TableDataInfo list(AreaBuildingFloor areaBuildingFloor) {
        startPage();
        List<AreaBuildingFloor> list = areaBuildingFloorService.queryPageList(areaBuildingFloor);
        return getDataTable(list);
    }

    /**
     * 导出区域楼栋楼层列表
     */
    @ApiOperation("导出区域楼栋楼层列表")
    @PreAuthorize("@ss.hasPermi('building:buildingFloor:export')")
    @Log(title = "区域楼栋楼层", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AreaBuildingFloor areaBuildingFloor) {
        List<AreaBuildingFloor> list = areaBuildingFloorService.queryPageList(areaBuildingFloor);
        ExcelUtil<AreaBuildingFloor> util = new ExcelUtil<AreaBuildingFloor>(AreaBuildingFloor.class);
        util.exportExcel(response, list, "区域楼栋楼层数据");
    }

    /**
     * 获取区域楼栋楼层详细信息
     */
    @ApiOperation("获取区域楼栋楼层详细信息")
    @PreAuthorize("@ss.hasPermi('building:buildingFloor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(areaBuildingFloorService.getById(id));
    }

    /**
     * 新增区域楼栋楼层
     */
    @ApiOperation("新增区域楼栋楼层")
    @PreAuthorize("@ss.hasPermi('building:buildingFloor:add')")
    @Log(title = "区域楼栋楼层", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody AreaBuildingFloor areaBuildingFloor) {
        areaBuildingFloor.setCreateBy(SecurityUtils.getUsername());
        areaBuildingFloor.setCreateTime(DateUtils.getNowDate());
        return toAjax(areaBuildingFloorService.save(areaBuildingFloor));
    }

    /**
     * 修改区域楼栋楼层
     */
    @ApiOperation("修改区域楼栋楼层")
    @PreAuthorize("@ss.hasPermi('building:buildingFloor:edit')")
    @Log(title = "区域楼栋楼层", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody AreaBuildingFloor areaBuildingFloor) {
        areaBuildingFloor.setUpdateBy(SecurityUtils.getUsername());
        areaBuildingFloor.setUpdateTime(DateUtils.getNowDate());
        return toAjax(areaBuildingFloorService.updateById(areaBuildingFloor));
    }

    /**
     * 删除区域楼栋楼层
     */
    @ApiOperation("删除区域楼栋楼层")
    @PreAuthorize("@ss.hasPermi('building:buildingFloor:remove')")
    @Log(title = "区域楼栋楼层", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(areaBuildingFloorService.removeBatchByIds(Arrays.asList(ids)));
    }

    /**
     * 获取树形结构
     */
    @ApiOperation("获取树形结构")
    @GetMapping("/treeList")
    public AjaxResult treeList(AreaBuildingFloor areaBuildingFloor){
        return success(areaBuildingFloorService.treeList(areaBuildingFloor));
    }
}
